define(["jquery","bbcare"],function($,$bb){
    var servers = {};
    var URL = $bb.baseUrl("followapp");

    /**
     * 查询用户评估信息
     */
    servers.ajaxRecordlist = function(params,callback){
        $bb.ajax({
            url: URL + "service/evaluation/recordlist",
            data: JSON.stringify({
                data: {
                    "evaluationType":"nbna",
                    "channelType":"2",
                    "queueUserId":params.userId,
                }
            }),
            success: function (data) {
                callback(data,params);
            }
        })
    }

    /**
     * 请求评估详情
     */
    servers.ajaxRecordDetail = function(params,callback){
        $bb.ajax({
            url: URL + "service/evaluation/getEvaluationDetail",
            data: JSON.stringify({
                data: {
                    "evaluationType":"nbna",
                    "channelType":"2",
                    "recordId":params.id,
                }
            }),
            success: function (data) {
                callback(data.data,params);
            }
        });
    }

    /**
     * 请求指导建议
     */
    servers.ajaxGuide = function(params,callback){
        $bb.ajax({
            url: URL + "service/evaluation/getGuide",
            data: JSON.stringify({
                data: {
                    "examinationPaperName":"nbna",
                    "channelType":"2",
                    "evaluationId":params.id,
                    "queueUserId":params.userId
                }
            }),
            success: function (data) {
                callback(data.data,params);
            }
        });
    }

    /**
     * 修改指导建议
     */
    servers.ajaxModifyGuides = function(params,callback){
        var channelId = $bb.getChannelId();
        $bb.ajax({
            url: URL + "service/evaluation/guidemodify",
            data: JSON.stringify({
                data: {
                    "channelType":"2",
                    "channelId":channelId,
                    "evaluationId":params.id,
                    "queueUserId":params.userId,
                    "guide":params.guide,
                    "remark":params.remark,
                }
            }),
            success: function (data) {
                callback(data.data,params);
            }
        });
    }

    /**
     * 处理nbna 历史记录数据
     */
    servers.handleHistoryData = function(list){
        for (var i = 0; i < list.length; i++) {
            list[i].testAge = $bb.simple.formatAge(list[i].ageDay);
        }
        return list;
    }

    /**
     * 获取当前记录id的索引
     */
    servers.getRecordIndex = function(list,params){
        for (var i = 0; i < list.length; i++) {
            if( list[i].id == params.id ){
                return i;
            }
        }
        return 0;
    }

    /**
     * 处理评测结果数据
     */
    servers.handleResult = function(data,width){
        data.testAge = $bb.simple.formatAge(data.ageDay);
        var othersWidth = width - 62*5;
        for(var key in data){
            if( key == "behaviorAbility" || key == "passiveMuscle" || key == "activeMuscles" || key == "originalReflection" || key == "generalResponse" ){
                if( data.totalScore * 1 > 0 ){
                    data[key+"Width"] = 100 * ( othersWidth * data[key] * 1 / data.totalScore + 62 ) / width + "%";
                }else{
                    data[key+"Width"] = "20%";
                }
            }
        }
        return data;
    }

    /**
     * 处理指导建议和备注数据
     */
    servers.handleGuide = function(data){
        if( !data ) data = {};
        if( !data.guide ) data.guide = "暂无指导建议";
        if( !data.remark ) data.remark = "暂无备注";
        return data;
    }

    return servers;
});